#ifndef XWindowPort_First
#define XWindowPort_First
#ifdef __GNUG__
#pragma interface
#endif

#include "X11.h"
#include "WindowPort.h"
#include "XWinSystem.h"
#include "XBitmap.h"

class XWindowPort: public WindowPort {
public:
	XDisplay    *dpy;
	XWindow     id;     // current drawable id
	XWindow     winid;  // window id
	GC          gc;     // window graphic context
	XWindowPort *father;
	XSizeHints  *sizehints;
	int         currpsz;
	int         solid;
	int         func;
	bool        active : 1;
	bool        focus : 1;
	bool        isicon : 1;
	bool        icon : 1;
	bool        configure : 1;
	bool        gavehints : 1;
	bool        ingrab : 1;

public:
	MetaDef(XWindowPort);
	bool MapEvent(XEvent &xe, Token *t= 0);
	void setLine(int psz);
	void SetLine(int psz)
		{ if (psz != currpsz) setLine(psz); }
	Point getMousePos(u_int&);
	void setFunction(int f);
	void SetFunction(int f)
		{ if (func != f) setFunction(f); }
	void SetFillStyle(int fs)
		{ if (solid != fs) { XSetFillStyle(XWinSystem::display, gc, solid= fs); } }
	void CopyArea(XWindow from, XWindow to, const Point &o, const Point &e, const Point &d);
	void UpdateHints(const Point &o, const Point &e);
	XWindow GetLeader();
	Point GetParentOrigin();
	Point GetMyOrigin();
public:
	XWindowPort(Window *bw, WindowType wt, GrCursor curs);
	~XWindowPort();

	XWindow GetWinId()
		{ return winid; }

	//---- window management
	void DevShow(WindowPort *father, const Rectangle&);
	void DevHide();
	void DevIconize();
	void DevTop(bool);
	void DevSetExtent(const Point&);
	void DevSetOrigin(const Point&);

	//---- clipping
	void DevClip(const Rectangle&);

	//---- graphic
	void DevStrokeLine2(int, const Rectangle&, GrLineCap, const Point&,
			const Point&);
	void DevStrokeRect2(int, const Rectangle&);
	void DevFillRect(const Rectangle&);
	void DevStrokeRRect2(int, const Rectangle&, const Point&);
	void DevFillRRect2(const Rectangle&, const Point&);
	void DevStrokeOval2(int, const Rectangle&);
	void DevFillOval2(const Rectangle&);
	void DevStrokeWedge2(int, GrLineCap, const Rectangle&, int, int);
	void DevFillWedge2(const Rectangle&, int, int);
	void DevStrokePolygon2(const Rectangle&, Point*, int, GrPolyType t,
											int psz, GrLineCap cap);
	void DevFillPolygon2(const Rectangle&, Point*, int, GrPolyType);
	void DevShowBitmap(const Rectangle&, Bitmap*);
	void DevShowChar(Font *fdp, const Point &pos, Rune c, const Rectangle&);
	void DevShowTextBatch(const Rectangle&, const Point&);
	void DevSetPattern(Bitmap*);
	void DevSetColor2(u_long id);
	void DevSetOther(int);

	//---- scrolling
	void DevScrollRect(const Rectangle&, const Point&);
		
	//---- input
	void DevFullscreen(bool);

	//---- cursor
	void DevSetCursor(GrCursor);

	//---- mouse
	void DevSetMousePos(const Point&, bool);

	//---- misc
	int DevGetId();
	void DevGiveHint(int, int, void*);
	void DevSetTitle(const char *t);
};

#endif
